}
static gboolean
-repo_get_string_key_inherit (OstreeRepo *repo,
- const char *section,
- const char *key,
- char **out_value,
- GError **error)
+repo_get_remote_option_inherit (OstreeRepo *self,
+ const char *remote_name,
+ const char *option_name,
+ char **out_value,
+ GError **error)
{
+ OstreeRepo *parent = ostree_repo_get_parent (self);
+ gs_free char *value = NULL;
gboolean ret = FALSE;
- GError *temp_error = NULL;
- GKeyFile *config;
- gs_free char *ret_value = NULL;
- config = ostree_repo_get_config (repo);
+ if (!_ostree_repo_get_remote_option (self, remote_name, option_name, NULL, &value, error))
+ goto out;
- ret_value = g_key_file_get_value (config, section, key, &temp_error);
- if (temp_error)
+ if (value == NULL && parent != NULL)
{
- OstreeRepo *parent = ostree_repo_get_parent (repo);
- if (parent &&
- (g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)
- || g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)))
- {
- g_clear_error (&temp_error);
- if (!repo_get_string_key_inherit (parent, section, key, &ret_value, error))
- goto out;
- }
- else
- {
- g_propagate_error (error, temp_error);
+ if (!repo_get_remote_option_inherit (parent, remote_name, option_name, &value, error))
goto out;
- }
}
+ /* Success here just means no error occurred during lookup,
+ * not necessarily that we found a value for the option name. */
+ ot_transfer_out_value (out_value, &value);
ret = TRUE;
- ot_transfer_out_value (out_value, &ret_value);
+
out:
return ret;
}
gboolean tls_permissive = FALSE;
OstreeFetcherConfigFlags fetcher_flags = 0;
guint i;
- gs_free char *remote_key = NULL;
gs_free char *path = NULL;
gs_free char *baseurl = NULL;
gs_free char *metalink_url_str = NULL;
gs_unref_object OstreeMetalink *metalink = NULL;
OtPullData pull_data_real = { 0, };
OtPullData *pull_data = &pull_data_real;
- GKeyFile *config = NULL;
GKeyFile *remote_config = NULL;
char **configured_branches = NULL;
guint64 bytes_transferred;
pull_data->start_time = g_get_monotonic_time ();
pull_data->remote_name = g_strdup (remote_name);
- config = ostree_repo_get_config (self);
-
- remote_key = g_strdup_printf ("remote \"%s\"", pull_data->remote_name);
- if (!g_key_file_has_group (config, remote_key))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "No remote '%s' found in " SYSCONFDIR "/ostree/remotes.d",
- remote_key);
- goto out;
- }
#ifdef HAVE_GPGME
- if (!ot_keyfile_get_boolean_with_default (config, remote_key, "gpg-verify",
- TRUE, &pull_data->gpg_verify, error))
+ if (!_ostree_repo_get_remote_boolean_option (self,
+ pull_data->remote_name, "gpg-verify",
+ TRUE, &pull_data->gpg_verify, error))
goto out;
#else
pull_data->gpg_verify = FALSE;
pull_data->phase = OSTREE_PULL_PHASE_FETCHING_REFS;
- if (!ot_keyfile_get_boolean_with_default (config, remote_key, "tls-permissive",
- FALSE, &tls_permissive, error))
+ if (!_ostree_repo_get_remote_boolean_option (self,
+ pull_data->remote_name, "tls-permissive",
+ FALSE, &tls_permissive, error))
goto out;
if (tls_permissive)
fetcher_flags |= OSTREE_FETCHER_FLAGS_TLS_PERMISSIVE;
gs_free char *tls_client_cert_path = NULL;
gs_free char *tls_client_key_path = NULL;
- if (!ot_keyfile_get_value_with_default (config, remote_key,
- "tls-client-cert-path",
- NULL, &tls_client_cert_path, error))
+ if (!_ostree_repo_get_remote_option (self,
+ pull_data->remote_name, "tls-client-cert-path",
+ NULL, &tls_client_cert_path, error))
goto out;
- if (!ot_keyfile_get_value_with_default (config, remote_key,
- "tls-client-key-path",
- NULL, &tls_client_key_path, error))
+ if (!_ostree_repo_get_remote_option (self,
+ pull_data->remote_name, "tls-client-key-path",
+ NULL, &tls_client_key_path, error))
goto out;
if ((tls_client_cert_path != NULL) != (tls_client_key_path != NULL))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "\"%s\" must specify both \"tls-client-cert-path\" and \"tls-client-key-path\"", remote_key);
+ "remote \"%s\" must specify both \"tls-client-cert-path\" and \"tls-client-key-path\"",
+ pull_data->remote_name);
goto out;
}
else if (tls_client_cert_path)
gs_free char *tls_ca_path = NULL;
gs_unref_object GTlsDatabase *db = NULL;
- if (!ot_keyfile_get_value_with_default (config, remote_key,
- "tls-ca-path",
- NULL, &tls_ca_path, error))
+ if (!_ostree_repo_get_remote_option (self,
+ pull_data->remote_name, "tls-ca-path",
+ NULL, &tls_ca_path, error))
goto out;
if (tls_ca_path)
{
gs_free char *http_proxy = NULL;
- if (!ot_keyfile_get_value_with_default (config, remote_key, "proxy",
- NULL, &http_proxy, error))
+ if (!_ostree_repo_get_remote_option (self,
+ pull_data->remote_name, "proxy",
+ NULL, &http_proxy, error))
goto out;
if (http_proxy)
_ostree_fetcher_set_proxy (pull_data->fetcher, http_proxy);
}
- if (!ot_keyfile_get_value_with_default (config, remote_key, "metalink",
- NULL, &metalink_url_str, error))
+ if (!_ostree_repo_get_remote_option (self,
+ pull_data->remote_name, "metalink",
+ NULL, &metalink_url_str, error))
goto out;
if (!metalink_url_str)
{
- if (!repo_get_string_key_inherit (self, remote_key, "url", &baseurl, error))
+ if (!repo_get_remote_option_inherit (self, pull_data->remote_name, "url", &baseurl, error))
goto out;
+ if (baseurl == NULL)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+ "No \"url\" option in remote \"%s\"",
+ pull_data->remote_name);
+ goto out;
+ }
+
pull_data->base_uri = soup_uri_new (baseurl);
if (!pull_data->base_uri)
goto out;
}
- configured_branches = g_key_file_get_string_list (config, remote_key, "branches", NULL, NULL);
+ if (!_ostree_repo_get_remote_list_option (self,
+ pull_data->remote_name, "branches",
+ &configured_branches, error))
+ goto out;
if (!load_remote_repo_config (pull_data, &remote_config, cancellable, error))
goto out;
return removed;
}
+gboolean
+_ostree_repo_get_remote_option (OstreeRepo *self,
+ const char *remote_name,
+ const char *option_name,
+ const char *default_value,
+ char **out_value,
+ GError **error)
+{
+ local_cleanup_remote OstreeRemote *remote = NULL;
+ gboolean ret = FALSE;
+
+ remote = ost_repo_get_remote (self, remote_name, error);
+
+ if (remote != NULL)
+ {
+ ret = ot_keyfile_get_value_with_default (remote->options,
+ remote->group,
+ option_name,
+ default_value,
+ out_value,
+ error);
+ }
+
+ return ret;
+}
+
+gboolean
+_ostree_repo_get_remote_list_option (OstreeRepo *self,
+ const char *remote_name,
+ const char *option_name,
+ char ***out_value,
+ GError **error)
+{
+ local_cleanup_remote OstreeRemote *remote = NULL;
+ gboolean ret = FALSE;
+
+ remote = ost_repo_get_remote (self, remote_name, error);
+
+ if (remote != NULL)
+ {
+ gs_strfreev char **value = NULL;
+ GError *local_error = NULL;
+
+ value = g_key_file_get_string_list (remote->options,
+ remote->group,
+ option_name,
+ NULL, &local_error);
+
+ /* Default value if key not found is always NULL. */
+ if (g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
+ g_clear_error (&local_error);
+
+ if (local_error == NULL)
+ {
+ ot_transfer_out_value (out_value, &value);
+ ret = TRUE;
+ }
+ }
+
+ return ret;
+}
+
+gboolean
+_ostree_repo_get_remote_boolean_option (OstreeRepo *self,
+ const char *remote_name,
+ const char *option_name,
+ gboolean default_value,
+ gboolean *out_value,
+ GError **error)
+{
+ local_cleanup_remote OstreeRemote *remote = NULL;
+ gboolean ret = FALSE;
+
+ remote = ost_repo_get_remote (self, remote_name, error);
+
+ if (remote != NULL)
+ {
+ ret = ot_keyfile_get_boolean_with_default (remote->options,
+ remote->group,
+ option_name,
+ default_value,
+ out_value,
+ error);
+ }
+
+ return ret;
+}
+
static void
ostree_repo_finalize (GObject *object)
{